#ifndef UTILS_H
#define UTILS_H
#include <stdint.h>
#include <QString>
#include <QDateTime>
#include "typedef.h"
bool isZero(float value);
float  Byte_to_Float(uint8_t byte[]);
uint16_t be_to_le(const uint16_t data);
uint16_t le_to_be(const uint16_t data);
uint16_t be_ctos(const uint8_t *buf);
int uint16Toint(uint16_t value);
uint16_t le_ctos(const uint8_t *buf);
uint8_t  hex2decimal(uint8_t);
uint8_t  decimal2hex(uint8_t);
void be_stoc(uint8_t *buf, uint16_t val);
void le_stoc(uint8_t *buf, uint16_t val);
uint32_t be_ctol(const uint8_t *buf);
uint32_t le_ctol(const uint8_t *buf);
void be_ltoc(uint8_t *buf, uint32_t val);
void le_ltoc(uint8_t *buf, uint32_t val);
void array_reverse(uint8_t *data,uint32_t length);
void printfArray(const uint8_t *data,uint32_t length);

bool judgeHostnameIsValid(const QString hostname);
bool judgeIPAddrIsValidQString(QString ipaddr);
bool checkStr2int(QString str,int &value);
bool checkStr2uint16(QString str,uint16_t &value);
bool checkStr2uint32(QString str,uint32_t &value);
bool checkStr2uint64(QString str,uint64_t &value);

bool checkStrHex2uint16(QString str,uint16_t &value);
bool checkStrHex2uint32(QString str,uint32_t &value);
bool checkStrHex2uint64(QString str,uint64_t &value);


bool checkStr2float(QString str,float &value);

bool isValidMacQString(const QString value);
bool isValidIpQString(const QString  value);

bool checkSensorNoValid(const QString serialno);


void getIpaddrBytes(const QString ipaddrstr,IPADDR ipaddr);
void getMacaddrBytes(const QString macaddrstr,MACADDR macaddr);
QString bytes2Str(const uint8_t *data,int len);
QString float2Str(float *data,int len);
float bytes2float(const uint8_t *data);
QString bytes2Ipaddr(const uint8_t *data);
QString bytes2MacAddr(const uint8_t *data);
uint64_t getTimeStamp();
 uint8_t bcd2decimal(uint8_t bcd_num);
void reverseBytesStep(uint8_t *data,int length);




#endif // UTILS_H
